home *** CD-ROM | disk | FTP | other *** search
- Q28519 Incorrect Code when Initializing Int to Unsigned Character
- C Compiler
- 5.00 5.10 | 5.10
- MS-DOS | OS/2
-
- Summary:
- The following program will print out failed even though the two
- variables k and j should be equal to each other. The problem only
- occurs if the expression has the following form:
-
- int int_var1 = unsigned_char_var1 = unsigned_char_var2 % number;
-
-
-
- main()
- {
- int loop;
-
-
- unsigned char i,j;
- i = 6;
- for (loop=0; loop < 1; ++loop) {
- int k = j = i%3; /* k and j should be equal */
- if ( k == j)
- {printf("Passed\n");
- exit(0);
- }
- else
- printf("Failed\n");
- exit(1);
- }
- }
-
- Microsoft has confirmed this to be a problem in Versions 5.00 and
- 5.10. We are researching this problem and will post new information
- as it becomes available.
-
- More Information:
- The compiler generates code for the byte modulus correctly; the
- result of this operation is in the AH register. However, the code that
- follows, zeros out the AH register for the conversion of the unsigned
- character to the signed integer. Thus, the integer variable does not
- get the correct value and the comparison fails.
- This problem can be worked around by doing the assignment in two
- different steps or by casting the modulus expression to be integer,
- as follows:
-
- int k = j = (int) i%3;
-
-
-
- Keywords: buglist5.00 buglist5.10 qfbv
- Updated 88/07/29 14:28
-